package handler

import (
	"article-hub/models"
	"article-hub/pkg"
	"github.com/gin-gonic/gin"
)

func UserAdd(c *gin.Context) {
	tel := c.PostForm("title")
	password := c.PostForm("password")

	if pkg.RegTel(tel) {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "手机号必须是11位的手机号",
		})
		return
	}

	user := models.User{
		Tel:      tel,
		Password: password,
	}
	err := models.DB.Create(&user).Debug().Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "注册失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "注册成功",
	})
	return
}
